//
// Created by wdq on 22-9-21.
//
#include <iostream>

using namespace std;

void quickSort(int nums[], int left, int right) {
    if (left >= right - 1) {
        return;
    }
    int pivot = nums[left];
    int i, j;
    for (i = left, j = right - 1; i < j;) {
        while (i <= right - 1 && nums[i] <= pivot) {
            i++;
        }
        while (j >= left && nums[j] > pivot) {
            j--;
        }
        if (i >= j) break;
        swap(nums[i], nums[j]);
    }
    swap(nums[left], nums[j]);
    quickSort(nums, left, j);
    quickSort(nums, j + 1, right);


}

int main() {

    int nums[] = {2, 6, 1, 56, 25, 67, 89, 5, 3, 3};
    printf("nums: ");
    for (auto &i: nums) {
        printf("%-4d ", i);
    }
    printf("\n");
    quickSort(nums, 0, sizeof(nums) / sizeof(int));
    printf("sorting..........................\n");
    printf("nums: ");
    for (auto &i: nums) {
        printf("%-4d ", i);
    }
    printf("\n");
    return 0;
}
